package com.zsc.wxm.ysh.anjo.es.utils;

import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;

import java.io.File;
import java.io.IOException;

/**
 * 描述：
 *
 * @author playmaker
 * @since 2021/2/13 22:27
 */
public class FileUtils {

    /**
     * 文件下载
     * @param url 文件url
     * @param dest 目录
     * @throws IOException
     */
    public static void downloadFile(String url, File dest) throws IOException {
        HttpGet httpGet = new HttpGet(url);
        try (CloseableHttpResponse response = HttpClientBuilder.create().build().execute(httpGet)) {
            org.apache.commons.io.FileUtils.writeByteArrayToFile(dest,
                    IOUtils.toByteArray(response.getEntity().getContent()));
        }
    }
}
